﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace Maticsoft.Web.sysMan
{
    public partial class ModifySingle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int singleId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(singleId);
                }
            }
        }

        private void ShowInfo(int singleId)
        {
            Maticsoft.BLL.singleInfo bll = new Maticsoft.BLL.singleInfo();
            Maticsoft.Model.singleInfo model = bll.GetModel(singleId);
            this.lblsingleId.Text = model.singleId.ToString();
            this.txtstitle.Text = model.stitle;
            this.txtsA.Text = model.sA;
            this.txtsB.Text = model.sB;
            this.txtsC.Text = model.sC;
            this.txtsD.Text = model.sD;
            this.txtskey.Text = model.skey;
            this.txtsscore.Text = model.sscore.ToString();
            this.txtstuType.Text = model.stuType;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtstitle.Text.Trim().Length == 0)
            {
                strErr += "单选题题目内容不能为空！\\n";
            }
            if (this.txtsA.Text.Trim().Length == 0)
            {
                strErr += "A不能为空！\\n";
            }
            if (this.txtsB.Text.Trim().Length == 0)
            {
                strErr += "B不能为空！\\n";
            }
            if (this.txtsC.Text.Trim().Length == 0)
            {
                strErr += "C不能为空！\\n";
            }
            if (this.txtsD.Text.Trim().Length == 0)
            {
                strErr += "D不能为空！\\n";
            }
            if (this.txtskey.Text.Trim().Length == 0)
            {
                strErr += "答案不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtsscore.Text))
            {
                strErr += "分值格式错误！\\n";
            }
            if (this.txtstuType.Text.Trim().Length == 0)
            {
                strErr += "stuType不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int singleId = int.Parse(this.lblsingleId.Text);
            string stitle = this.txtstitle.Text;
            string sA = this.txtsA.Text;
            string sB = this.txtsB.Text;
            string sC = this.txtsC.Text;
            string sD = this.txtsD.Text;
            string skey = this.txtskey.Text;
            decimal sscore = decimal.Parse(this.txtsscore.Text);
            string stuType = this.txtstuType.Text;


            Maticsoft.Model.singleInfo model = new Maticsoft.Model.singleInfo();
            model.singleId = singleId;
            model.stitle = stitle;
            model.sA = sA;
            model.sB = sB;
            model.sC = sC;
            model.sD = sD;
            model.skey = skey;
            model.sscore = sscore;
            model.stuType = stuType;

            Maticsoft.BLL.singleInfo bll = new Maticsoft.BLL.singleInfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListSingle.aspx");

        }


       
    }
}